package com.example.yygh.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.result.Result;
import com.example.ylgh.model.user.UserInfo;
import com.example.ylgh.vo.acl.UserQueryVo;
import com.example.ylgh.vo.user.UserInfoQueryVo;
import com.example.yygh.user.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author hx
 * @create 2022/5/24 13:50
 * description:
 */
@RestController
@RequestMapping("/admin/user")
public class UserController {
    @Autowired
    private UserInfoService userInfoService;

    /**
     * 带条件分页查询
     * @param limit
     * @param page
     * @param userInfoQueryVo
     * @return
     */
    @GetMapping("/{page}/{limit}")
    public Result list(@PathVariable Long limit,
                       @PathVariable Long page,
                       UserInfoQueryVo userInfoQueryVo){
        Page<UserInfo> pageParam = new Page<>(page,limit);
        IPage<UserInfo> result =userInfoService.selectPage(pageParam,userInfoQueryVo);
        return Result.ok(result);
    }

    /**
     * 用户锁定
     * @param status
     * @param userId
     * @return
     */
    @GetMapping("/lock/{userId}/{status}")
    public Result lock(@PathVariable Integer status, @PathVariable Long userId){
        userInfoService.lock(userId,status);
        return Result.ok();
    }

    /**
     * 用户详情
     * @param userId
     * @return
     */
    @GetMapping("/show/{userId}")
    public Result show(@PathVariable Long userId){
        Map<String, Object> map =userInfoService.show(userId);
        return Result.ok(map);
    }

    /**
     * 认证审批
     * @param authStatus
     * @param userId
     * @return
     */
    @GetMapping("/approval/{userId}/{authStatus}")
    public Result approval(@PathVariable Integer authStatus, @PathVariable Long userId){
        userInfoService.approval(userId,authStatus);
        return Result.ok();

    }
}
